package com.marcandjo.gwtproject.client;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.marcandjo.gwtproject.client.model.Category;
import com.marcandjo.gwtproject.client.model.Photo;
import com.marcandjo.gwtproject.client.model.PhotoModelFactory;

public class NavigationBar extends Composite implements ValueChangeHandler<String>
{
	public NavigationBar()
	{
		initWidget(createUi());
	}

	private LayoutPanel createUi()
	{
		LayoutPanel panel = new LayoutPanel();
		panel.setStyleName("appl-navigation");

		VerticalPanel vPanel = new VerticalPanel();
		for (Category category : PhotoModelFactory.getInstance().getModel())
		{
			for (Photo photo : category.getPhotos())
			{
				Hyperlink link = new Hyperlink(photo.getDescription(), photo.getId());

				vPanel.add(link);
			}
		}
		
		panel.add(vPanel);

		// Add history listener
	    History.addValueChangeHandler(this);

	    // Now that we've setup our listener, fire the initial history state.
	    History.fireCurrentHistoryState();
		
		return panel;
  }

  public void onValueChange(ValueChangeEvent<String> event) {
    // This method is called whenever the application's history changes. Set
    // the label to reflect the current history token.
  }
}
